//
//  MFWJsonUtils.m
//  MFWSdk
//
//  Created by Song Xiaofeng on 13-7-26.
//  Copyright (c) 2013年 Mafengwo Inc. All rights reserved.
//

#import "MFWJsonUtils.h"

@implementation MFWJsonUtils

+ (id)mutableParseJsonData:(NSData*)data;
{
    return [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
}
+ (id)mutableParseJsonString:(NSString*)jsonStr;
{
    return [self mutableParseJsonData:[jsonStr dataUsingEncoding:NSUTF8StringEncoding]];
}

+ (id)parseJsonData:(NSData*)data;
{
    if (data)
    {
        return [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
    }
    
    return nil;
}

+ (id)parseJsonString:(NSString *)jsonStr
{
    return [self parseJsonData:[jsonStr dataUsingEncoding:NSUTF8StringEncoding]];
}

+ (NSData*)dataEncodingJsonObject:(id)obj;
{
    return [NSJSONSerialization dataWithJSONObject:obj options:kNilOptions error:nil];
}

+ (NSString*)stringEncodingJsonObject:(id)obj;
{
    if (!obj)
    {
        return nil;
    }
    NSData *jsonRawData = [self dataEncodingJsonObject:obj];
    return [[NSString alloc] initWithData:jsonRawData encoding:NSUTF8StringEncoding];
}

@end
